package com.xhs.zdl.demo;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.xhs.zdl.demo.ListViewFragment.ListViewActivity;
import com.xhs.zdl.demo.addressChoose.ChooseAddressActivity;
import com.xhs.zdl.demo.gridViewDemo.GridViewDemo;
import com.xhs.zdl.demo.adapter.NormalListViewAdapter;
import com.xhs.zdl.demo.expandableListView.ExpandableListViewDemo;
import com.xhs.zdl.demo.imageRoll.ImageRoll;
import com.xhs.zdl.demo.citypickerview.CitypickerviewDemo;
import com.xhs.zdl.demo.itemHasImageOrVideo.PakeUpImgVideoActivity;
import com.xhs.zdl.demo.radioButton.HomePageDemo;
import com.xhs.zdl.demo.SmartRefresh.SmartRefreshActivity;
import com.xhs.zdl.demo.treeNode.TreeNodeActivity;
import com.xhs.zdl.demo.webView.WebViewDemo;
import com.xhs.zdl.demo.wheelCamera.WheelCameraActivity;
import com.xhs.zdl.demo.zxing.ZXingDemo;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    private ListView listView;
    private ArrayList<String> data;
    private NormalListViewAdapter adapter;
    private ArrayList<Class> classData;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        findView();
        initView();
    }

    /**
     * 初始化数据
     */
    private void initView() {
        //listView的数据源
        data = new ArrayList<>();
        //listView的adapter
        adapter = new NormalListViewAdapter(this, data);
        //绑定listView
        listView.setAdapter(adapter);

        //添加listView的item数据
        data.add("expandableListView");
        data.add("imageRoll");
        data.add("webView");
        data.add("homePage");
        data.add("ZXing");
        data.add("GridViewDemo");
        data.add("CityPickerView");
        data.add("ChooseAddress");
        data.add("WheelCameraActivity");
        data.add("PakeUpImgVideoActivity");
        data.add("ListViewActivity");
        data.add("SmartRefreshActivity");
        data.add("TreeNodeActivity");
        adapter.notifyDataSetChanged();

        //点击item后，跳转的界面的数据源
        classData = new ArrayList<>();
        classData.add(ExpandableListViewDemo.class);
        classData.add(ImageRoll.class);
        classData.add(WebViewDemo.class);
        classData.add(HomePageDemo.class);
        classData.add(ZXingDemo.class);
        classData.add(GridViewDemo.class);
        classData.add(CitypickerviewDemo.class);
        classData.add(ChooseAddressActivity.class);
        classData.add(WheelCameraActivity.class);
        classData.add(PakeUpImgVideoActivity.class);
        classData.add(ListViewActivity.class);
        classData.add(SmartRefreshActivity.class);
        classData.add(TreeNodeActivity.class);

        //绑定item的监听器
        listView.setOnItemClickListener(onItemClickListener);
    }

    /**
     * 找到控件
     */
    private void findView() {
        listView = (ListView) findViewById(R.id.listView);
    }

    /**
     * 首页listView中item的点击事件
     */
    AdapterView.OnItemClickListener onItemClickListener = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            startActivity(new Intent(MainActivity.this, classData.get(i)));
        }
    };
}
